package com.byxy.service.impl;

import com.byxy.dao.AdminRuleDao;
import com.byxy.model.AdminRule;
import com.byxy.service.AdminRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
@Transactional
public class AdminRuleServiceImpl implements AdminRuleService {
    @Autowired
    private AdminRuleDao adminRuleDao;

    @Override
    public void save(AdminRule adminRule) {
        adminRuleDao.save(adminRule);
    }

    @Override
    public void delete(Integer[] ids) {
        for (int id : ids) {
            adminRuleDao.delete(id);
        }
    }

    @Override
    public void update(AdminRule adminRule) {
        adminRuleDao.update(adminRule);
    }

    @Override
    public AdminRule get(Integer id) {
        return adminRuleDao.get(id);
    }

    @Override
    public List<AdminRule> listPage(Integer pageNum, Integer pageSize, String search) {
        return adminRuleDao.listPage(pageNum, pageSize, search);
    }

    @Override
    public Integer count(String search) {
        return adminRuleDao.count(search);
    }

    @Override
    public void enable(Integer[] ids) {
        for (int id : ids) {
            AdminRule adminRule = adminRuleDao.get(id);
            adminRule.setStatus(true);
            adminRuleDao.update(adminRule);
        }
    }

    @Override
    public void disable(Integer[] ids) {
        for (int id : ids) {
            AdminRule adminRule = adminRuleDao.get(id);
            adminRule.setStatus(false);
            adminRuleDao.update(adminRule);
        }
    }
}
